﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KimPhongCRM.Models;
using DevExpress.Web.Mvc;

namespace KimPhongCRM.Controllers
{
    [PermissionFilter]
    public class ThongKeController : BaseController
    {
        //
        // GET: /ThongKe/
        KimPhongCRM.Models.Entities db = new Models.Entities();
        [MvcSiteMapProvider.MvcSiteMapNode(Title = "Thống kê", Key = "ThongKe", Clickable = true, ParentKey = "Home")]
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult TongHop()
        {
            Dictionary<string, int> dic = new Dictionary<string, int>();
            int chuyendi = Convert.ToInt32(Math.Round((decimal)db.tblTourKHs.Count(cd => cd.ngayDiTour < DateTime.Now) / db.tblTourKHs.Count(), 2) * 100);
            int tour = Convert.ToInt32(Math.Round((decimal)db.tblTourKHs.Count(cd => cd.ngayDiTour < DateTime.Now) / db.tblTourKHs.Count(), 2) * 100);
            dic.Add("chuyendi",chuyendi);
            ViewData["TongHop"] = dic;
            return PartialView();
        }
        public ActionResult TheVip()
        {
            List<sp_ThongKe_TheVip_Result> model = db.sp_ThongKe_TheVip().ToList();
            return PartialView(model);
        }
        public ActionResult BieuDoCapThe()
        {
            return PartialView();
        }
       public JsonResult jsBieuDoCapThe()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
           int y = DateTime.Now.Year;
           int m = DateTime.Now.Month;

            for (int i = 1; i <= m; i++)
            {
                List<sp_ThongKe_BangCapThe_Result> tk = new  List<sp_ThongKe_BangCapThe_Result>();
                tk = db.sp_ThongKe_BangCapThe(y, i).ToList();
                if (tk != null)
                {
                    dic.Add(i.ToString(), tk);
                }
            }
            string js = Lib.convertParameters.strparameter(dic);
            return Json(js,JsonRequestBehavior.AllowGet);
        }
        //Danh sách khách hàng tham gia nhiều tour nhất
        public ActionResult TopKhachHangTour()
        {
            List<sp_ThongKe_TopKHTour_Result> model = db.sp_ThongKe_TopKHTour().ToList();
            return PartialView(model);
        }
        //Danh sách khách hàng có tổng điểm cao nhất
        public ActionResult TopKhachHangDiem()
        {
            List<sp_ThongKe_TopKHDiem_Result> model = db.sp_ThongKe_TopKHDiem().ToList();
            return PartialView(model);
        }
        //Danh sách tour có được tham gia nhiều nhất
        public ActionResult TopTourHot()
        {
            List<sp_ThongKe_TopTourHot_Result> model = db.sp_ThongKe_TopTourHot().ToList();
            return PartialView(model);
        }
    }
}
